package net.zhengxinyun.performance.service.exportService;

import net.zhengxinyun.performance.Util.DateUtils;
import net.zhengxinyun.performance.filter.IncentiveFilter;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;

import java.util.List;

public class JiliTypeExce {

    Workbook OtherFujianItem(Workbook wb, List<IncentiveFilter> list, CellStyle style,int sheetAt)
    {

        Sheet sheet = wb.getSheetAt(sheetAt);
        int rows = 4;
        int i =0;
        double sumScore= 0.0;

        Row rowdate = sheet.getRow(2);
        if(rowdate==null)
        {
            rowdate= sheet.createRow(5);
        }
        Cell celldate = rowdate.getCell(5);
        //cell0.setCellStyle(style);
        String reportDate = DateUtils.getCurrentDate();
        celldate.setCellValue("填报日期："+reportDate.substring(0,4)+"年"+reportDate.substring(4,6)+"月"+reportDate.substring(6,8)+"日"); // 序号


        for (IncentiveFilter item : list) {
            i++;
            Row row = sheet.getRow(rows);
            if(row==null)
            {
                row= sheet.createRow(rows);
            }
            Cell cell0 = row.createCell(0);
            cell0.setCellStyle(style);
            cell0.setCellValue(i); // 序号

            Cell cell1 = row.createCell(1);
            cell1.setCellValue(item.getIncentive()); // 激励事项
            cell1.setCellStyle(style);

            Cell cell2 = row.createCell(2);
            cell2.setCellValue(item.getRecognitionUnit()); // 表彰单位
            cell2.setCellStyle(style);

            Cell cell3 = row.createCell(3);
            cell3.setCellValue(item.getCommendedUnit()); // 被表彰单位
            cell3.setCellStyle(style);

            Cell cell4 = row.createCell(4);
            cell4.setCellValue(item.getItemName()); // 计分情形类别
            cell4.setCellStyle(style);

            Cell cell5 = row.createCell(5);
            cell5.setCellValue(item.getFileName()); // 作证材料
            cell5.setCellStyle(style);

            Cell cell6 = row.createCell(6);
            cell6.setCellValue(item.getPoint()); // 分值
            cell6.setCellStyle(style);
            sumScore=sumScore+Double.parseDouble(item.getPoint());

            rows++;

        }
        if(list.size()>0)
        {
            Row  row  = sheet.getRow(rows);
            if(row==null)
            {
                row= sheet.createRow(rows);
            }
            CellRangeAddress region = new CellRangeAddress(rows,rows,0,1);
            sheet.addMergedRegion(region);
            RegionUtil.setBorderBottom(1,region,sheet,wb);
            RegionUtil.setBorderLeft(1,region,sheet,wb);
            RegionUtil.setBorderRight(1,region,sheet,wb);
            RegionUtil.setBorderTop(1,region,sheet,wb);

            Cell heji = row.createCell(0);

            heji.setCellValue("汇总得分"); // 备注
            heji.setCellStyle(style);



            Cell hejiSum = row.createCell(2);
            region = new CellRangeAddress(rows,rows,2,6);
            RegionUtil.setBorderBottom(1,region,sheet,wb);
            RegionUtil.setBorderLeft(1,region,sheet,wb);
            RegionUtil.setBorderRight(1,region,sheet,wb);
            RegionUtil.setBorderTop(1,region,sheet,wb);
            sheet.addMergedRegion(region);
            hejiSum.setCellValue(sumScore+"分"); //
            hejiSum.setCellStyle(style);
        }



        return  wb;
    }
}
